package com.dodoke.controller;

import java.util.List;

import com.dodoke.domain.WxImage;
import com.dodoke.service.IWxImageService;
import io.swagger.annotations.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.dodoke.common.annotation.Log;
import com.dodoke.common.core.controller.BaseController;
import com.dodoke.common.core.domain.AjaxResult;
import com.dodoke.common.enums.BusinessType;
import com.dodoke.common.utils.poi.ExcelUtil;
import com.dodoke.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 【图片】Controller
 * 
 * @author dodoke
 * @date 2020-08-25
 */
@RestController
@RequestMapping("/image")
@Api("商品图片模块")
public class WxImageController extends BaseController
{
    @Autowired
    private IWxImageService wxImageService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('wx:image:list')")
    @GetMapping("/list")
    public TableDataInfo list(WxImage wxImage)
    {
        startPage();
        List<WxImage> list = wxImageService.selectWxImageList(wxImage);
        return getDataTable(list);
    }

    @ApiOperation("根据商品id查询商品对应的图片集合")
    @ApiImplicitParam(name = "goodsId",value = "商品id",paramType = "head")
    @RequestMapping(value = "/selectImagesBygoodsId/{goodsId}",method = RequestMethod.GET)
    public AjaxResult selectImagesBygoodsId(@PathVariable Long goodsId){
        return AjaxResult.success(wxImageService.selectWxImageByGoodsId(goodsId));
    }

    /***
     * 上传图片
     * @param images
     * @return
     */
    @ApiOperation("新增图片")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "images",value = "要上传的图片",paramType = "query"),
            @ApiImplicitParam(name = "goodsId",value = "商品id",paramType = "path"),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "图片上传成功"),
            @ApiResponse(code = 500, message = "图片上传失败")
    })
    @RequestMapping(value = "/addWxImages/{goodsId}",method = RequestMethod.POST)
    public AjaxResult addWxImages(@PathVariable Long goodsId, @RequestParam("file") MultipartFile[] images){
        return toAjax(wxImageService.insertWxImage(goodsId,images));
    }

    /***
     * 删除图片
     * @return
     */
    @ApiOperation("删除图片")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wxImage",value = "wxImage实体类",paramType = "body"),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "图片删除成功"),
            @ApiResponse(code = 500, message = "图片删除失败")
    })
    @RequestMapping(value = "/deleteWxImage",method = RequestMethod.DELETE)
    public AjaxResult deleteWxImageById(WxImage wxImage){
        return toAjax(wxImageService.deleteWxImageById(wxImage));
    }


    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('wx:image:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WxImage wxImage)
    {
        List<WxImage> list = wxImageService.selectWxImageList(wxImage);
        ExcelUtil<WxImage> util = new ExcelUtil<WxImage>(WxImage.class);
        return util.exportExcel(list, "image");
    }




}
